﻿<%@ Page Title="" Language="C#" MasterPageFile="~/AdminCP/Layouts/Admin.Master" AutoEventWireup="true"
    CodeBehind="WebForm2.aspx.cs" Inherits="MLM.AdminCP.Pages.WebForm2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    Product Management
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            // <![CDATA[
            //On insert and update buttons click temporarily disables ajax to perform upload actions
            function conditionalPostback(sender, eventArgs) {
                var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig");
                if (eventArgs.get_eventTarget().match(theRegexp)) {
                    var upload = $find(window['UploadId']);

                    //AJAX is disabled only if file is selected for upload
                    if (upload.getFileInputs()[0].value != "") {
                        eventArgs.set_enableAjax(false);
                    }
                }
            }

            function validateRadUpload(source, e) {
                e.IsValid = false;

                var upload = $find(source.parentNode.getElementsByTagName('div')[0].id);
                var inputs = upload.getFileInputs();
                for (var i = 0; i < inputs.length; i++) {
                    //check for empty string or invalid extension
                    if (inputs[i].value != "" && upload.isExtensionValid(inputs[i].value)) {
                        e.IsValid = true;
                        break;
                    }
                }
            }
            // ]]>
        </script>
    </telerik:RadCodeBlock>
    <telerik:RadAjaxPanel ID="RadAjaxPanel2" runat="server" ClientEvents-OnRequestStart="conditionalPostback">
        <telerik:RadProgressManager ID="RadProgressManager1" runat="server"></telerik:RadProgressManager>
        <telerik:RadProgressArea ID="RadProgressArea1" runat="server">
        </telerik:RadProgressArea>
        <telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" DataSourceID="GroupProductEds" AllowAutomaticInserts="True"
            AllowAutomaticUpdates="True" AllowAutomaticDeletes="True" ShowStatusBar="True"
            GridLines="None" OnItemDataBound="RadGrid1_ItemDataBound" OnItemCreated="RadGrid1_ItemCreated"
            PageSize="4">
            <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="ProductBaseID" DataSourceID="GroupProductEds">
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton">
                        <HeaderStyle Width="36px"></HeaderStyle>
                    </telerik:GridEditCommandColumn>
                    <telerik:GridTemplateColumn HeaderText="Image Name" UniqueName="Name" SortExpression="Name">
                        <ItemTemplate>
                            <asp:Label runat="server" ID="lblName" Text='<%# Eval("Name") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadTextBox runat="server" Width="200px" ID="txbName" Text='<%# Bind("Name") %>'>
                            </telerik:RadTextBox>
                            <asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" ControlToValidate="txbName"
                                ErrorMessage="Please, enter a name!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
                        </EditItemTemplate>
                        <HeaderStyle Width="120px"></HeaderStyle>
                    </telerik:GridTemplateColumn>
                    
                    <telerik:GridBinaryImageColumn DataField="ThumbImage" HeaderText="Image" UniqueName="Upload"
                        ImageHeight="80px" ImageWidth="80px" ResizeMode="Fit" DataAlternateTextField="Name"
                        DataAlternateTextFormatString="Image of {0}">
                        <HeaderStyle Width="10%" HorizontalAlign="Center"></HeaderStyle>
                        <ItemStyle CssClass="binaryImage"></ItemStyle>
                    </telerik:GridBinaryImageColumn>
                    <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton">
                        <HeaderStyle Width="36px"></HeaderStyle>
                    </telerik:GridButtonColumn>
                </Columns>
                <EditFormSettings>
                    <EditColumn ButtonType="ImageButton">
                    </EditColumn>
                </EditFormSettings>
            </MasterTableView>
        </telerik:RadGrid>
    </telerik:RadAjaxPanel>
    <asp:EntityDataSource ID="GroupProductEds" runat="server" ConnectionString="name=MLMDataContext"
        DefaultContainerName="MLMDataContext" EnableFlattening="False" 
        EntitySetName="ProductBases" EnableDelete="True" EnableInsert="True" 
        EnableUpdate="True" EntityTypeFilter="ProductBas">
    </asp:EntityDataSource>
</asp:Content>
